#define _CRT_SECURE_NO_WARNINGS 1
#include "String.h"
#include <string>

void teststring1()
{
	String::string s1("hello world");
	cout << s1.c_str() << endl;

	String::string s2;
	cout << s2.c_str() << endl;
	//string s;
	//cout << s << endl;

	int i = 0;
	//for (i = 0; i < s1.size(); i++)
	//{
	//	s1[i]++;
	//}
	//cout << endl;

	for (i = 0; i < s1.size(); i++)
	{
		cout << s1[i] << ' ';
	}
	cout << endl;


	//const String::string s3("hello hello");
	//for (i = 0; i < s3.size(); i++)
	//{
	//	s3[i]++;
	//}
	//cout << endl;

	String::string::iterator it = s1.begin();
	while (it != s1.end())
	{
		cout << *it << ' ';
		it++;
	}
	cout << endl;

	for (auto ch : s1)
	{
		cout << ch << ' ';
	}

}
void teststring2()
{
	const String::string s1("hello world");
	String::string::const_iterator it = s1.begin();
	while (it != s1.end())
	{
		cout << *it << ' ';
		it++;
	}
	cout << endl;

	for (auto ch : s1)
	{
		cout << ch << ' ';
	}
}

void teststring3()
{
	String::string s1("hello world");
	cout << s1.c_str() << endl;
	s1.pushback('!');
	cout << s1.c_str() << endl;
	s1.append("hello world");
	cout << s1.c_str() << endl;

	String::string s2("hello world");
	cout << s2.c_str() << endl;
	s2 += '!';
	cout << s2.c_str() << endl;
	s2 += "hello world";
	cout << s2.c_str() << endl;


	String::string s3("hello world");
	cout << s3.c_str() << endl;
	s3.insert(0, 5, 'x');
	cout << s3.c_str() << endl;
	s3.insert1(0, 5, 'e');
	cout << s3.c_str() << endl;

	s3.erase(5, 4);
	cout << s3.c_str() << endl;

}


void teststring4()
{
	String::string url = "ftp://www.baidu.com/?tn=65081411_1_oem_dg";

	size_t pos1 = url.find("://");
	if (pos1 != String::string::npos)
	{
		String::string protocol = url.substr(0, pos1);
		cout << protocol.c_str() << endl;
	}

	size_t pos2 = url.find('/', pos1 + 3);
	if (pos2 != String::string::npos)
	{
		String::string domain = url.substr(pos1 + 3, pos2 - (pos1 + 3));
		String::string uri = url.substr(pos2 + 1);

		cout << domain.c_str() << endl;
		cout << uri.c_str() << endl;
	}
}

void teststring5()
{
	String::string s("hello world");
	s.resize(8);
	cout << s.c_str() << endl;
	s.resize(13, 'x');
	cout << s.c_str() << endl;

	s.resize(20, 'y');
	cout << s.c_str() << endl;

	cout << s;
}

void teststring6()
{
	String::string s("hello world");
	s += '\0';
	s += "xxxxxx";

	cout << s.c_str() << endl;
	cout << s << endl;
}
void teststring7()
{
	String::string s;
	cin >> s;
	cout << s << endl;
	cin >> s;
	cout << s << endl;

}
void teststring8()
{
	//String::string s1("hello world");
	//s1 += '\0';
	//s1 += "xxxxx";

	//String::string s2("hello world");
	//s2 += '\0';
	//s2 += "yyyyy";
	//cout << (s2 < s1) << endl;

	//cout << (s2 == s1) << endl;
	String::string s1("hello");
	String::string s2("hello");
	cout << (s1 < s2) << endl;
	cout << (s1 > s2) << endl;
	cout << (s1 == s2) << endl << endl;


	String::string s3("hello");
	String::string s4("helloxxx");
	cout << (s3 < s4) << endl;
	cout << (s3 > s4) << endl;
	cout << (s3 == s4) << endl << endl;


	String::string s5("helloxxx");
	String::string s6("hello");
	cout << (s5 < s6) << endl;
	cout << (s5 > s6) << endl;
	cout << (s5 == s6) << endl << endl;

	s6 = s5;
	cout << s6 << endl;

}
void teststring9()
{
	std::string s("hello world");
	cout << sizeof(s) << endl;
}

int main()
{
	//teststring1();
	//teststring2();
	//teststring3();
	//teststring4();
	//teststring8();
	teststring9();
	return 0;
}